package ac.zlf.springmybatis.admin.bjui.util;

import ac.zlf.springmybatis.util.CommonValidate;

import javax.servlet.http.HttpServletRequest;

/**
 * web输入校验类
 * Created by chenjie on 2015/4/16.
 */
public class WebUtils {


    /**
     * 获得跟路径，这个路径包括IP及端口
     * @return
     */
    public static String getFullRoot(HttpServletRequest request) {
        String serverName = request.getServerName();
        Integer port = request.getServerPort();
        String contextPath = request.getContextPath();
        StringBuilder root = new StringBuilder("http://");
        root.append(serverName);
        if(port != null && port != 80) {
            root.append(":");
            root.append(port);
        }
        if(CommonValidate.isNotEmpty(contextPath)) {
            root.append(contextPath);
        }
        return root.toString();
    }

}
